<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="codec" uri="/WEB-INF/tld/codec.tld"%>
<%@ include file="/WEB-INF/common/taglibs.jsp"%>

<script>
function getRules(){
	var rules = "";
	$(".filterdata").each(
			function(index, value) {
				if ($(this).attr("type") ==='checkbox'){
					if ($( this ).is(":checked")){
						rules +=getRuleByInput(this);
					}
					
				}else{
				if ($(this).val()) {
					rules += getRuleByInput(this);
				}
				}
			});
	var value =	$("#reportType").val();
	rules += getFilterString(value,'gp','xxx')
 	rules = rules.substring(0, rules.length - 1)
 return	'{\"groupOp\":\"AND\",\"rules\":[' + rules + ']}';
 }

function getRuleByInput(obj) {
	var op = $(obj).attr("op");
	var field = $(obj).attr("field");
	var data = $(obj).val();
	return  getFilterString(field,op,data);
}

function getFilterString(field,op,data){
	return '{"field":"' + field + '","op":"' + op
	+ '","data":"' + data + '"},';
	
}
$(document).ready(function(){
	$("#report").click(function(){
		var rule = getRules();
 		 $("#report-form").find("input[name='filter']").val(rule);		
 		$("#report-form").submit();
	});

	
});

</script>

<form id="report-form" method="post">
<input type="hidden" name="filter">
<input type="hidden" name="linkType" value="product">
</form>


		<div class="row-fluid">
				<div class="box">
					<div class="title">
 						<h4>
							<span class="icon16 icomoon-icon-filter"></span> <span>Filter</span>
							<span class="box-form right">
  							<a href="#" id="report" class="btn btn-mini btn-success">Submit</a></span>
  						</h4>
						<a href="#" class="minimize">Minimize</a>
					</div>
					<div class="content clearfix form-horizontal">
 						<div class="form-row row-fluid">
 					 
							
							<div class="span4">
								<label class="form-label span6">Report Type</label>
								<div class="span6 controls">
									<select id="reportType" >
										<option value="dayTag" <c:if test="${gpdayTag ne null}">selected=selected</c:if>> Daily</option>
 										<option value="weekTag" <c:if test="${gpweekTag ne null}">selected</c:if>>Week</option>
										<option value="monthTag" <c:if test="${gpmonthTag ne null}">selected</c:if>>Month</option>
										<option value="yearTag" <c:if test="${gpyearTag ne null}">selected</c:if>>Year</option>
									</select>
								</div>
							</div>
							
							
							
							<div class="span4">
								<label class="form-label span6">Status</label>
								<div class="span6 controls">
									<select field="orderStatus" class="filterdata" op="eq">
										<option value="">====================</option>
										 <c:if
														test="${not empty orderStatuses}">
														<c:forEach var="single" items="${orderStatuses}">
															<option value="${single}"
																${(single == eqorderStatus)?'selected':'' }>${single}</option>
														</c:forEach>
										</c:if>

									</select>
								</div>
							</div>
						</div>
						<div class="form-row row-fluid">
							<div class="span4">
								<label class="form-label span6">Date added Start</label> <input
									class="filterdata span6 datepicker" type="text" field="time" op="ge" value="${gedateAdd}"/>
							</div>
							<div class="span4">
								<label class="form-label span6">Date added End</label> <input
									class="filterdata span6 datepicker" type="text" field="time" op="le" value="${ledateAdd}"/>
							</div>
						</div>
						<hr />


					</div>
				</div>
		 
		</div>
<div class="row-fluid">
	<div class="span12">
		<div class="box gradient">
			<div class="title">
				<h4>
					<span>Sales Report Manager </span> <span class="box-form right">
					</span>
				</h4>


				<a href="#" class="minimize"></a>
			</div>

<div class="content scrollable clearfix">
<table class="dynamicTable display table table-bordered">
	<thead>
<tr>
<th>Name </th>
<th>CalculateStart </th>
<th>Increase Count </th>
<th>Increase Amount </th>
<th>Deduct Count </th>
<th>Deduct Amount </th>
<th>Balance </th>
</tr>
	</thead>
	<tbody>
		<c:set var="allEntity" value="${requestScope.page.result}" />
		<c:if test="${allEntity!=null}">
			<c:forEach var="entity" items="${allEntity}">
				<tr>
					<td>${entity.name}</td>
				
					<td>${entity.calculateFrom}</td>
				
					<td>${entity.increaseCount}</td>

					<td>${entity.increase}</td>
 
					<td>${entity.deductCount}</td>

					<td>${entity.deduct}</td>
					
					<td>${entity.balance}</td>
 

				</tr>
			</c:forEach>
		</c:if>
	</tbody>
</table>
</div>

		</div>
	</div>
</div>
